package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.kaili.basic.mapper.PushPushgroupMapper;
import com.kaili.basic.pojo.entity.MdmPushEntity;
import com.kaili.basic.pojo.entity.MdmPushPushgroupEntity;
import com.kaili.basic.service.IMdmPushPushgroupSerivce;
import org.springframework.stereotype.Service;
import java.util.List;


/**
 * @Desc: 推送管理ServiceImpl
 * @author: jianfeng
 * @Time: 2019/7/31 10:34
 * @Copyright: © 2018 杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅, 禁止外泄或用于其它商业目的
 */
@Service
public class PushPushgroupSerivceImpl extends ServiceImpl<PushPushgroupMapper, MdmPushPushgroupEntity> implements IMdmPushPushgroupSerivce {

    /**
    * @Desc:  新增
    * @author: jianfeng
    * @Time: 2019/8/1 14:44
    * @param entity
    * @return java.lang.Boolean
    */
    @Override
    public Boolean add(MdmPushEntity entity) {
        List<MdmPushPushgroupEntity> pspList = entity.getPsp();
        for(MdmPushPushgroupEntity psp : pspList){
            psp.setPushId(entity.getId());
        }
        this.insertBatch(pspList);

        return true;
    }

    /**
    * @Desc:  修改关联表
    * @author: jianfeng
    * @Time: 2019/8/1 10:58
    * @param entity
    * @return java.lang.Boolean
    */
    @Override
    public Boolean modify(MdmPushEntity entity) {
        //1、先删除关联表对应关系
        this.del(entity.getId());
        //2、在添加对应关联表信息
        this.add(entity);
        return true;
    }

    /**
    * @Desc:  根据push_id删除
    * @author: jianfeng
    * @Time: 2019/8/1 11:07
    * @param id
    * @return java.lang.Boolean
    */
    @Override
    public Boolean del(Integer id) {
        Wrapper<MdmPushPushgroupEntity> wrapper=new EntityWrapper<>();
        wrapper.where("push_id={0}",id);
        this.delete(wrapper);
        return true;
    }


}
